/// Creator:      fengliang
/// CreatDate:    2021-03-12
/// Description:  输液工作量统计表
Class Nur.MNISV3.IPIFWorkLoad Extends %Persistent [ ClassType = persistent, Owner = {_SYSTEM}, ProcedureBlock ]
{

/// 操作日期
Property WorkDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required, SqlColumnNumber = 2 ];

/// 操作时间
Property WorkTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required, SqlColumnNumber = 3 ];

/// 操作人 
Property WorkUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 4 ];

/// 操作医嘱
Property WorkOeoreId As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 5 ];

/// 操作类型
Property WorkType As CF.NUR.MNISV3.IPIFWorkType [ SqlColumnNumber = 6 ];

/// 操作失败次数 
Property WorkFailureNum As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 7 ];

/// 操作时科室
Property WorkLoc As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 8 ];

/// 操作时输液情况
Property WorkInfusionState As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 9 ];

/// 操作时输液情况原因 
Property WorkInfusionReason As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 10 ];

/// 操作时输液情况措施
Property WorkInfusionMeasure As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 11 ];

/// 操作时输液滴速
Property WorkInfusionSpeed As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 12 ];

/// 穿刺部位
Property WorkPuncturePart As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 13 ];

/// 余液
Property WorkResidualQty As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 14 ];

Index Date On WorkDate;

Index UserDate On (WorkUser, WorkDate);

Index LocDate On (WorkLoc, WorkDate);

Index Oeore On (WorkOeoreId, WorkType);

Index OeoreDateTime On (WorkOeoreId, WorkDate, WorkTime);

/// Creator:      lmm
/// CreatDate:    2019-04-24
/// Description:  工作量保存
/// Input：       parr:数据串(key|value^key|value),id:id,userId:用户ID,locId:科室ID,oeoreId:执行记录ID,WorkType:操作类型
/// other:        w ##class(Nur.MNISV3.IPIFWorkLoad).Save()
ClassMethod Save(parr As %String, id As %String, userId As %String, locId As %String, oeoreId As %String, workType As %String) As %String
{
    s tmp=""
    s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    i (id=""){
        s rec=##class(Nur.MNISV3.IPIFWorkLoad).%New()
    }else{
        s rec=##class(Nur.MNISV3.IPIFWorkLoad).%OpenId(id)
    }
    i '$d(tmp("WorkDate"))  d
    .s tmp("WorkDate")=+$h
    i '$d(tmp("WorkTime"))  d
    .s tmp("WorkTime")=$p($h,",",2)

    i $d(tmp("WorkDate")) s rec.WorkDate=tmp("WorkDate")
    i $d(tmp("WorkTime")) s rec.WorkTime=tmp("WorkTime")
    i $d(tmp("WorkFailureNum")) s rec.WorkFailureNum=tmp("WorkFailureNum")  
    i $d(tmp("WorkInfusionState")) s rec.WorkInfusionState=tmp("WorkInfusionState")
    i $d(tmp("WorkInfusionReason")) s rec.WorkInfusionReason=tmp("WorkInfusionReason")
    i $d(tmp("WorkInfusionMeasure")) s rec.WorkInfusionMeasure=tmp("WorkInfusionMeasure")
    i $d(tmp("WorkInfusionSpeed")) s rec.WorkInfusionSpeed=tmp("WorkInfusionSpeed")
    i $d(tmp("WorkPuncturePart")) s rec.WorkPuncturePart=tmp("WorkPuncturePart")
    i $d(tmp("WorkResidualQty")) s rec.WorkResidualQty=tmp("WorkResidualQty")
    s rec.WorkType=##class(CF.NUR.MNISV3.IPIFWorkType).%OpenId(workType)
    s rec.WorkOeoreId=oeoreId
    s rec.WorkLoc=locId
    s rec.WorkUser=userId
    b ;bb1
    s sc=rec.%Save()
    s id=rec.%Id()
    d rec.%Close()
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q id
}

/// Creator:      lmm
/// CreatDate:    2019-11-27
/// Description:  工作量删除
/// Input：       parr:数据串(key|value^key|value),id:id,userId:用户ID,locId:科室ID,oeoreId:执行记录ID,WorkType:操作类型
/// other:        w ##class(Nur.MNISV3.IPIFWorkLoad).Delete()
ClassMethod Delete(oeoreId, workType As %String) As %String
{
    s oeoreId=$replace(oeoreId,"-","||")
    s workId=""
    f 
    {
       s workId=$o(^Nur.MNISV3.IPIFWorkLoadI("Oeore"," "_oeoreId,workType,workId))
       q:workId=""
       s rec=##class(Nur.MNISV3.IPIFWorkLoad).%OpenId(workId)
       d rec.%DeleteId(workId)
    }
    q 0
}

/// Creator:      lmm
/// CreatDate:    2019-11-27
/// Description:  工作量删除
/// Input：       parr:数据串(key|value^key|value),id:id,userId:用户ID,locId:科室ID,oeoreId:执行记录ID,WorkType:操作类型
/// other:        w ##class(Nur.MNISV3.IPIFWorkLoad).Delete()
ClassMethod DeleteById(workId As %String) As %String
{
    s rec=##class(Nur.MNISV3.IPIFWorkLoad).%OpenId(workId)
    d rec.%DeleteId(workId)
    q 0
}

Storage Default
{
<Data name="IPIFWorkLoadDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>WorkDate</Value>
</Value>
<Value name="3">
<Value>WorkTime</Value>
</Value>
<Value name="4">
<Value>WorkUser</Value>
</Value>
<Value name="5">
<Value>WorkOeoreId</Value>
</Value>
<Value name="6">
<Value>WorkType</Value>
</Value>
<Value name="7">
<Value>WorkFailureNum</Value>
</Value>
<Value name="8">
<Value>WorkLoc</Value>
</Value>
<Value name="9">
<Value>WorkInfusionState</Value>
</Value>
<Value name="10">
<Value>WorkInfusionReason</Value>
</Value>
<Value name="11">
<Value>WorkInfusionMeasure</Value>
</Value>
<Value name="12">
<Value>WorkInfusionSpeed</Value>
</Value>
<Value name="13">
<Value>WorkPuncturePart</Value>
</Value>
<Value name="14">
<Value>WorkResidualQty</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.IPIFWorkLoadD</DataLocation>
<DefaultData>IPIFWorkLoadDefaultData</DefaultData>
<IdLocation>^Nur.MNISV3.IPIFWorkLoadD</IdLocation>
<IndexLocation>^Nur.MNISV3.IPIFWorkLoadI</IndexLocation>
<StreamLocation>^Nur.MNISV3.IPIFWorkLoadS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
